/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */

package base.Items;

import com.jme3.export.InputCapsule;
import com.jme3.export.JmeExporter;
import com.jme3.export.JmeImporter;
import com.jme3.export.OutputCapsule;
import com.jme3.export.Savable;
import java.io.IOException;

/**
 *
 * @author Paulo
 */
public class Item implements Comparable<Item>, Savable {
    private String name;
    private double weight;
    private int stack;
    
    public Item(String name, double weight, int stack) {
        this.name = name;
        this.weight = weight;
        this.stack = stack;
    }
    
    public String getName() {
        return this.name;
    }
    
    public double getWeight() {
        return this.weight;
    }
    
    public int getStack() {
        return this.stack;
    }
    
    public void setWeight(double value) {
        this.weight = value;
    }
    
    public void setName(String value) {
        this.name = value;
    }
    
    public void setStack(int value) {
        this.stack = value;
    }

    public int compareTo(Item o) {
        return this.name.compareToIgnoreCase(o.name);
    }

    public void write(JmeExporter ex) throws IOException {
        OutputCapsule out = ex.getCapsule(this);
        
        out.write(name, "name", null);
        out.write(weight, "weight", 0);
        out.write(stack, "stack", 0);
    }

    public void read(JmeImporter im) throws IOException {
        InputCapsule in = im.getCapsule(this);
        
        name = in.readString("name", null);
        weight = in.readInt("weight", 0);
        stack = in.readInt("stack", 0);
    }
}
